package models

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

type Power struct {
	gorm.Model
	PowerName  string `json:"powername" form:"powername" gorm:"type:varchar(20);not null unique"  binding:"required"`
	PowerPath  string `json:"powerpath" form:"powerpath" gorm:"type:varchar(20);not null" binding:"required"`
	PowerLevel string `json:"powerlevel" form:"powerlevel" gorm:"type:varchar(20);not null"  binding:"required"`
}

// 获取单个权限
func GetPower(c *gin.Context) (Power, error) {
	json := make(map[string]interface{})
	c.ShouldBind(&json)
	powername := json["powername"]

	var power Power
	err := db.Table("powers").Where("powername = ?", powername).First(&power).Error
	return power, err
}

// 获取所有权利列表
func GetAllPower(c *gin.Context) ([]Power, error) {
	var powerdata []Power
	err := db.Table("powers").Find(&powerdata).Error
	return powerdata, err
}
